import smtplib
from email.mime.text import  MIMEText

#通过python来发送邮件

# 需要开启所有邮箱的SMTP服务，并开启所有邮箱客户端的授权密码
# 第三方SMTP服务
mial_host = "smtp.163.com" #设置服务器
mail_user = "xx@163.com"    #邮箱用户名
mail_pass = "xxxx"  #这里输入邮箱客户端授权码

sender = "xxx@163.com"
receivers = ["xx@qq.com","xxx@163.com"]

message = MIMEText("这是正文：你好，我是。。","plain", "utf-8")
message["From"] = sender
message["To"] = ";".join(receivers)
message["Subject"] = "第一封测试邮件"

try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mial_host,25)
    smtpObj.login(mail_user,mail_pass)
    smtpObj.sendmail(sender,receivers,message.as_string())
    print("发送成功")
except smtplib.SMTPException as e:
    print(f"发送失败，错误原因：{e}")